//
//  SJUserDefaultTool.m
//  Init
//
//  Created by zhaoshijie on 01/01/2018.
//  Copyright © 2018 zhaoshijie. All rights reserved.
//

#import "SJUserDefaultTool.h"

@implementation SJUserDefaultTool


/**
 数据写入沙盒的Library/Preference下，建议只保存应用的所有偏好设置

 @param obj obj
 @param key Key
 */
+ (void)userDefaultSetObjectWithObj:(id)obj
                                key:(NSString *)key
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:obj forKey:key];
    
    //  同步数据
    [userDefaults synchronize];
}



/**
 数据读取
 
 @param key Key
 @return value
 */
+ (id)userDefaultGainObjectWithKey:(NSString *)key
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    id value = [userDefaults objectForKey:key];
    return value;
}


/**
 数据清除
 
 @param key Key
 */
+ (void)userDefaultRemoveObjectWithKey:(NSString *)key
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:key];
    
    //  同步数据
    [userDefaults synchronize];
}

@end
